package org.framework.wu.framework.queue;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

/**
 * 消息定义类，实现Serializable接口以便于持久化
 */
public class Message implements Serializable {
    private static final long serialVersionUID = 1L;
    
    private String id;           // 消息唯一标识
    private String topic;        // 消息主题
    private Object body;         // 消息内容
    private Date timestamp;      // 消息创建时间
    private int retryCount;      // 重试次数
    
    public Message() {
        this.id = UUID.randomUUID().toString();
        this.timestamp = new Date();
        this.retryCount = 0;
    }
    
    public Message(String topic, Object body) {
        this();
        this.topic = topic;
        this.body = body;
    }
    
    // Getters and Setters
    public String getId() {
        return id;
    }
    
    public void setId(String id) {
        this.id = id;
    }
    
    public String getTopic() {
        return topic;
    }
    
    public void setTopic(String topic) {
        this.topic = topic;
    }
    
    public Object getBody() {
        return body;
    }
    
    public void setBody(Object body) {
        this.body = body;
    }
    
    public Date getTimestamp() {
        return timestamp;
    }
    
    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }
    
    public int getRetryCount() {
        return retryCount;
    }
    
    public void incrementRetryCount() {
        this.retryCount++;
    }
    
    @Override
    public String toString() {
        return "Message{" +
                "id='" + id + '\'' +
                ", topic='" + topic + '\'' +
                ", timestamp=" + timestamp +
                ", retryCount=" + retryCount +
                ", body=" + body +
                '}';
    }
}
